﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WorkFlowBLL;

namespace QLCF.Forms.admin
{
    public partial class popupAddAdminInRole : Form
    {
        frmAdmin frmAd = null;
        int roleID = -1;
        public popupAddAdminInRole()
        {
            InitializeComponent();
        }
        public popupAddAdminInRole(frmAdmin m_frmAdmin, int m_roleId)
        {
            InitializeComponent();
            frmAd = m_frmAdmin;
            roleID = m_roleId;            
            LoadAdmin();
        }        

        public void LoadAdmin()
        {            
            CtrAdmin ctrA = new CtrAdmin();
            var admins = ctrA.GetListAdminNotInRole(roleID);
            foreach (var admin in admins.Items)
            {
                ListViewItem item = new ListViewItem(admin.UserName);
                item.Tag = admin.AdminID;
                item.SubItems.Add(admin.FullName);                
                lstAdmin.Items.Add(item);
            }
        }        

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string strAdminIds="";
            foreach (ListViewItem item in lstAdmin.CheckedItems)
            {
                strAdminIds += "," + item.Tag;
            }
            if (strAdminIds != "")
                strAdminIds = strAdminIds.Substring(1);
            frmAd.addAdminsIntoRole(strAdminIds);
            this.Close();
        }        
    }
}
